package org.tigris.atlas.quizme.service.impl;

import java.lang.String;
import java.util.List;

import org.tigris.atlas.messages.Message;
import org.tigris.atlas.messages.MessageUtils;
import org.tigris.atlas.quizme.bizobj.UserProfileBO;
import org.tigris.atlas.quizme.service.UserProfileServiceResponse;

import org.tigris.atlas.quizme.service.AuthenticateService;
import org.tigris.atlas.quizme.transfer.UserProfile;

/**
 * Service implementation class for the Authenticate service
 * 
 * @author Robert Simmering
 */
public class AuthenticateServiceImpl extends AuthenticateServiceBaseImpl{

	/**
	 * Execute the Authenticate service
	 *
	 * @return UserProfileServiceResponse
	 */
	public void authenticateImpl(String username, String password, UserProfileServiceResponse response) {
		// Service business logic here
		List profiles = UserProfileBO.authenticate(username, password);
		if(profiles == null || profiles.size() != 1){
			Message msg = MessageUtils.createErrorMessage("errors.invalid.login", null, null);
			response.getMessages().addMessage(msg);
		}
		UserProfileBO profile = (UserProfileBO)profiles.get(0);
		
		response.setUserProfile(profile.getUserProfileValues());
	}

}